﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Kooboo.Web.Areas.Commerce.Binders;
using Kooboo.Commerce;

using Kooboo.IoC;

namespace Kooboo.Web.Binder
{
    public class CartItemBinder:EntityBinder
    {
        protected override string[] SkipProperties
        {
            get
            {
                return new string[] { "Product", "ProductPriceAttributeValue" };
            }
        }


        protected override object CreateModel(System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ModelBindingContext bindingContext, Type modelType)
        {
            var item = ObjectContainer.CreateInstance<ICartItem>();

            var form = controllerContext.HttpContext.Request.Form;

            var productId = form["ProductId"];
            if (productId != null)
            {
                var product = ObjectContainer.CreateInstance<IProduct>();

                product.Id = int.Parse(productId);

                item.Product = product;
            }

            var priceValueId = form["PriceValueId"];

            //if (string.IsNullOrWhiteSpace(priceValueId) == false)
            //{
            //    var pricevalue = ObjectContainer.CreateInstance<IProductPriceAttributeValue>();
            //    pricevalue.Id = int.Parse(priceValueId);

            //    item.ProductPriceAttributeValue = pricevalue;
            //}

            return item;
        }

   
    }
}